package com.usian.interceptor;

import com.usian.pojo.User;
import com.usian.pojo.Zhuce;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
//                             Object handler)throws Exception {
//        //从session中获取用户的信息， true 放行   false 拦截
//        User user = (User) request.getSession().getAttribute("user");
//        if(user!=null){
//            return true;
//        }
//        response.sendRedirect(request.getContextPath()+"/login/toLogin");
//        return false;
//    }
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
                             Object handler)throws Exception {
        //从session中获取用户的信息， true 放行   false 拦截
        Zhuce zhuce = (Zhuce) request.getSession().getAttribute("zhuce");
        if(zhuce!=null){
            return true;
        }
        response.sendRedirect(request.getContextPath()+"/clzc/toClzc");
        return false;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response,
                           Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response,
                                Object handler, Exception ex)throws Exception {
    }
}
